'''
实现一个自动取款机的存取款模拟效果。
要求有登陆和退出、查询余额、取钱，存钱等操作。
'''

#定义一个字典来存储用户信息
user = [
    {'account_name':'mayun','password':'123','money':'10000'},
    {'account_name':'mahuateng','password':'456','money':'5000'},
    {'account_name':'leijun','password':'789','money':'3000'}]

#登录页面
a1 = a2 = a3 = a4 =1 	#结束外循环
message = 0		#记录用户信息
while(a1):
    print("="*13,"欢迎使用自助存取款机","="*13)
    print(" "*13,end=" ")
    account_name = input("请输入账户名:")
    for i in range(len(user)):		#判断用户名是否存在
        if account_name == user[i]['account_name']:
            a1 = 0
            break
    else:
        print("账户名不存在！请重新输入！")
        continue
            
#密码输入界面
while(a2):
    print(" "*13,end=" ")
    account_name = input("请输入密码:")
    for i in range(len(user)):		#检验登录密码
        if account_name == user[i]['password']:
            a2 = 0
            message = i
            break
    else:
        print("密码错误！请选择：")
        print("{:16}{}".format(" ","1.重新输入"))
        print("{:16}{}".format(" ","2.退    出"))
        key = input("请输入您要进行的操作: ")
        if key == "1":
            continue
        if key == "2":
            a2 = 0
            a3 = 0
            print("="*13,"     欢迎下次使用!     ","="*13)
while(a3):
#登录成功后的界面
    print("="*13,"请选择您要进行的操作","="*13)
    print("{:16}{}".format(" ","1.存    款"))
    print("{:16}{}".format(" ","2.取    款"))
    print("{:16}{}".format(" ","3.查 询 余 额"))
    print("{:16}{}".format(" ","4.退    出"))
    key = input("请选择操作指令: ")

#键入指令，执行操作
    if key == "1":
        print("="*13,"   请输入存款金额   ","="*13)
        money = input()
        user[message]['money'] = str(int(user[message]['money']) + int(money))
        print("="*13,"存款成功","="*13)
        input("按回车键继续: ")       
    elif key == "2":
        while(a3):
            print("="*13,"   请输入取款金额   ","="*13)
            money = input()
            if int(user[message]['money']) >= int(money):
                user[message]['money'] = str(int(user[message]['money']) - int(money))
                print("="*13," 取款成功 ","="*13)
                input("按回车键继续: ")
                a4 = 0
                break
            else:
                print("账户余额不足,请重新输入")
                continue
    elif key == "3":
        print("="*13," 您账户中的余额为: ",user[message]['money'],"="*13)
        input("按回车键继续: ")
    elif key == "4":
        print("="*13,"     欢迎下次使用!     ","="*13)
        break   
    else:
        print("="*13,"输入有误，请重新输入","="*13)